package gizmoball;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class RecBrick extends Brick
{
	private int height = 20;
	private int width = 40;
	
	public RecBrick(int x,int y)
	{
		super(x,y);
	}
	
	public RecBrick(int x,int y,int p,int d)//The value of d can only be 0 or 90
	{
		super(x,y,p,d);
		if(d == 90)
			rotation();
	}
	
	public RecBrick(RecBrick b)
	{
		super(b);
		this.height = b.height;
		this.width = b.width;
	}
	
	public void setBrickx(int brickx) 
	{
		this.brickx = brickx;
	}
	
	public void setBricky(int bricky) 
	{
		this.bricky = bricky;
	}
	
	
	public void rotation()
	{
		this.direction += 90;
		int temp;
		temp = this.height;
		this.height = this.width;
		this.width = temp;
		if(this.direction == 180)
			this.direction = 0;
	}
	
	public void large()
	{
		if(this.direction == 0)
		{
			if(this.width<=80)
			{
				this.width = this.width*2;
				this.height = this.height*2;
			}
		}
		else
		{
			if(this.height<=80)
			{
				this.width = this.width*2;
				this.height = this.height*2;
			}
		}
	}
	
	public void small()
	{
		if(this.direction == 0)
		{
			if(this.width>=40)
			{
				this.width = this.width/2;
				this.height = this.height/2;
			}
		}
		else
		{
			if(this.height>=40)
			{
				this.width = this.width/2;
				this.height = this.height/2;
			}
		}
	}
	
	//return height of the rectangle, and make sure that height is the shorter side
	public int getHeight() 
	{
		return height;
	}

	public void setHeight(int height) 
	{
		this.height = height;
	}

	public  int getWidth() 
	{
		return width;
	}

	public void setWidth(int width) 
	{
		this.width = width;
	}
	

	public void paint(Graphics g)//
	{
    	// the "clip rectangle" is the area of the screen that needs to be
        // modified
        Rectangle clipRect = g.getClipBounds();
        Rectangle brick = new Rectangle(brickx,bricky,width,height);
        // For this tiny program, testing whether we need to redraw is
        // kind of silly.  But when there are lots of objects all over the
        // screen this is a very important performance optimization
        if (clipRect.intersects(brick)) 
       	{
       		Color c1 = new Color(153,0,0);
        	if(this.property == 1) 
        		c1 = new Color(108,123,139);
       		g.setColor(c1);
       		g.fillRect(brickx,bricky, width, height);
       		g.setColor(Color.black);
       		g.drawRect(brickx, bricky, width, height);
       	}
	}
	
	public int judge (int x, int y, int radius)
	{
		if(x>=this.brickx && x<=this.brickx+this.width
			&& y+radius>=this.bricky && y+radius/2<=this.bricky)
		{
			this.bump = 0;	
			return 0;
		}
		else if(x>=this.brickx && x<=this.brickx+this.width
				&& y-radius<=this.bricky+this.height && y-radius/2>=this.bricky+this.height)
		{
			this.bump = 0;
			return 180;
		}
		else if(y>=this.bricky && y<=this.bricky+this.height
				&& x+radius>=this.brickx && x+radius/2<=this.brickx)
		{
			this.bump = 0;
			return 270;
		}
		else if(y>=this.bricky && y<=this.bricky+this.height
				&& x-radius<=this.brickx+this.width && x-radius/2>=this.brickx+this.width)
		{
			this.bump = 0;
			return 90;
		}	
		else
			return -1;		
	}
	
	public int judge(int x, int y){
		if( x >= this.brickx && x <= this.brickx + this.width 
			&& y >= this.bricky && y <= this.bricky +this.height)
			return -3;
		else
			return -1;
	}
	
}

